package com.wh.helloword;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.ConfirmListener;
import com.rabbitmq.client.Connection;
import com.wh.utils.ConnectionUtil;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @Auther: HuiEr
 * @Date: 2020/3/11 14:14
 * @Description
 */
public class Producer {
    private static final String QUEUE_NAME="helloworld_queue";
    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = ConnectionUtil.getConnection();
        Channel channel = connection.createChannel();
        channel.confirmSelect();
        channel.addConfirmListener(new ConfirmListener() {
            @Override
            public void handleAck(long l, boolean b) throws IOException {
                System.out.println("confirm消息成功发送。。。");
            }

            @Override
            public void handleNack(long l, boolean b) throws IOException {
                System.out.println("confirm消息猥琐发送。。。");

            }
        });
        channel.queueDeclare(QUEUE_NAME,false,false,false,null);
        channel.basicPublish("",QUEUE_NAME,null,"helloworld模型的一条消息".getBytes());
    }
}
